from rest_framework import serializers
from mexam import models


class booktype(serializers.ModelSerializer):
    class Meta:
        model = models.booktype
        fields = '__all__'


class booklist(serializers.ModelSerializer):
    typename = serializers.SerializerMethodField()
    authorname = serializers.SerializerMethodField()

    def get_typename(self, obj):
        return obj.booktype.name

    def get_authorname(self, obj):
        return obj.author.name
    class Meta:
        model = models.book
        fields = '__all__'


class author(serializers.ModelSerializer):
    class Meta:
        model = models.author
        fields = '__all__'
